home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / bor_ti.exe / TI1030.ASC < prev    next >
Text File  |  1992-11-11  |  7KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1030
  9.   VERSION  :  3.x
  10.        OS  :  DOS
  11.      DATE  :  November 11, 1992                        PAGE  :  1/4
  12.  
  13.     TITLE  :  Using XFCBs to set/remove Volume Labels
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.     /* ------------------ [ SET VOLUME LABEL ] ----------------- *\
  22.     | Finding the volume label of a particular Media can be       |
  23.     | achieved with the findfirst() function of the Borland C/C++ |
  24.     | compilers.   Modifying the Volume Label, however, requires  |
  25.     | using Extended File Control Blocks.  The following function |
  26.     | ( and Macros ) can be used to Set and Remove Volume Labels. |
  27.     \* --------------------------------------------------------- */
  28.  
  29.  
  30.   #include <mem.h>
  31.   #include <dos.h>
  32.  
  33.  
  34.   #pragma option -a-
  35.   struct  EXTENDEDFCB
  36.   {
  37.       char    extSignature    ;
  38.       char    extReserved1[5] ;
  39.       char    extAttribute    ;
  40.       char    extDriveID      ;
  41.       char    extFileName[8]  ;
  42.       char    extExtent[3]    ;
  43.       short   extCurBlockNo   ;
  44.       short   extRecSize      ;
  45.       char    extFileSize[4]  ;
  46.       short   extFileDate     ;
  47.       short   extFileTime     ;
  48.       char    extReserved2[8] ;
  49.       char    extCurRecNo     ;
  50.       char    extRandonRecNo[4];
  51.   };
  52.   #pragma option -a.
  53.  
  54.  
  55.  
  56.  
  57.   /* -------------------- [ FCB MACROS ]----------------------- *\
  58.   | The following MACROS take advantage of Borland C++'s         |
  59.   | pseudoregisters and the __emit__() function to create a      |
  60.   | wrapper around INT 21, FUNCTIONS 13H and 16H which allow for |
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1030
  75.   VERSION  :  3.x
  76.        OS  :  DOS
  77.      DATE  :  November 11, 1992                        PAGE  :  2/4
  78.  
  79.     TITLE  :  Using XFCBs to set/remove Volume Labels.
  80.  
  81.  
  82.  
  83.  
  84.   | the deletion and creation of FILES using FCBS.  The MACRO can|
  85.   | be passed either an FCB or and Extended FCB structure with   |
  86.   | the various fields already initialized.   The result of the  |
  87.   | operation is kept in the AL register...                      |
  88.   \* ---------------------------------------------------------- */
  89.   #define CreateFCB( xfcb ) __emit__( 0x1E ); /* PUSH DS    */\
  90.             _AH = 0x2F;             /* Get Current DTA      */\
  91.             geninterrupt( 0x21 );   /* Call Upon DOS..      */\
  92.             __emit__( 0x06, 0x53 ); /* PUSH ES - PUSH BX    */\
  93.             _DS = FP_SEG( &xfcb );  /* Load Seg. of New DTA */\
  94.             _DX = FP_OFF( &xfcb );  /* Load Off. of New DTA */\
  95.             _AH = 0x1A;             /* Set DTA Function..   */\
  96.             geninterrupt( 0x21 );   /* Call Upon DOS        */\
  97.             _AH = 0x16;             /* Create File Function */\
  98.             geninterrupt( 0x21 );   /* Call Upon DOS        */\
  99.             __emit__( 0x5A, 0x1F ); /* POP DX  - POP  DS    */\
  100.             __emit__( 0x50 );       /* PUSH AX ( results )  */\
  101.             _AH = 0x1A;             /* Set ( Restore ) DTA  */\
  102.             geninterrupt( 0x21 );   /* Call Upon DOS        */\
  103.             __emit__( 0x58 );       /* Restore Results...   */\
  104.             __emit__( 0x1F );       /* Restore DS value...  */
  105.  
  106.   #define DeleteFCB( xfcb )  __emit__( 0x1E ); /* PUSH DS   */\
  107.             _AH = 0x2F;             /* Get Current DTA      */\
  108.             geninterrupt( 0x21 );   /* Call Upon DOS..      */\
  109.             __emit__( 0x06, 0x53 ); /* PUSH ES - PUSH BX    */\
  110.             _DS = FP_SEG( &xfcb );  /* Load Seg. of New DTA */\
  111.             _DX = FP_OFF( &xfcb );  /* Load Off. of New DTA */\
  112.             _AH = 0x1A;             /* Set DTA Function..   */\
  113.             geninterrupt( 0x21 );   /* Call Upon DOS        */\
  114.             _AH = 0x13;             /* Delete File Function */\
  115.             geninterrupt( 0x21 );   /* Call Upon DOS        */\
  116.             __emit__( 0x5A, 0x1F ); /* POP DX  - POP  DS    */\
  117.             __emit__( 0x50 );       /* PUSH AX ( results )  */\
  118.             _AH = 0x1A;             /* Set ( Restore ) DTA  */\
  119.             geninterrupt( 0x21 );   /* Call Upon DOS        */\
  120.             __emit__( 0x58 );       /* Restore Results...   */\
  121.             __emit__( 0x1F );       /* Restore DS value...  */
  122.  
  123.  
  124.  
  125.  
  126.   /* --------------- [ SET VOLUME LABEL ]--------------------- *\
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1030
  141.   VERSION  :  3.x
  142.        OS  :  DOS
  143.      DATE  :  November 11, 1992                        PAGE  :  3/4
  144.  
  145.     TITLE  :  Using XFCBs to set/remove Volume Labels.
  146.  
  147.  
  148.  
  149.  
  150.   |  This function modifies the VOLUME LABEL of the specified   |
  151.   |  Drive using extended FCBs.  The parameters are as follows: |
  152.   |  driveNum:   0 for current, 1 for A:, 2 for B:, 3 for C: etc|
  153.   |  Label   :   ASCIIZ string containing new label ( If NULL   |
  154.   |              current label is merely removed ).             |
  155.   |  RETURNS :   0x00-Successful                 0xFF-Failed    |
  156.   \* --------------------------------------------------------- */
  157.   int SetVolLabel( int driveNum, char *Label )
  158.   {
  159.       char *p;
  160.       struct EXTENDEDFCB  xfcb;
  161.  
  162.       memset(( void * )&xfcb, 0x20, sizeof( xfcb ));
  163.  
  164.       xfcb.extSignature = 0xFF;   /* Signal Extended FCB */
  165.       xfcb.extAttribute = 0x08;   /* Volume's Attribute  */
  166.       xfcb.extDriveID   = ( char )driveNum;  /* Drive ID.*/
  167.  
  168.       memset(( void * )xfcb.extFileName, '?', 11 );
  169.       DeleteFCB( xfcb );          /* Delete any LABEL    */
  170.  
  171.       if ( !Label )               /* NULL Label ?        */
  172.           return(( int )_AL );    /* Just return if YES..*/
  173.  
  174.       memset(( void * )xfcb.extFileName, ' ', 11 );
  175.       for( p = xfcb.extFileName;
  176.            p < ( char * )&xfcb.extCurBlockNo;
  177.            p++ )
  178.       {
  179.           if ( *Label == NULL )
  180.               break;
  181.           *p = *Label++;
  182.       }
  183.       CreateFCB( xfcb );          /* Create New Label..  */
  184.       return(( int )_AL );        /* Return Results..    */
  185.   }
  186.  
  187.  
  188.  
  189.  
  190.   int main( int argc, char *argv[] )
  191.   {
  192.       if ( argc > 1 )
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1030
  207.   VERSION  :  3.x
  208.        OS  :  DOS
  209.      DATE  :  November 11, 1992                        PAGE  :  4/4
  210.  
  211.     TITLE  :  Using XFCBs to set/remove Volume Labels.
  212.  
  213.  
  214.  
  215.  
  216.           SetVolLabel( 0, argv[1] ); /* Set Label of Local  */
  217.       else
  218.           SetVolLabel( 0, NULL );    /* Clear Label of Local*/
  219.       return( 0 );
  220.   }
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.